<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="./assets/favicon.ico">
    <link rel="stylesheet" href="./styles/index.scss">
    <title>Yank Note</title>
    <script>
      // 强制 monaco-editor 使用 浏览器模式
      window.nodeRequire = window.require
      window.nodeProcess = window.process
      window.nodeModule = window.module
      window.require = undefined
      window.process = undefined
      window.module = undefined

      // initial theme
      window.document.documentElement.setAttribute('app-theme', JSON.parse(localStorage['app.theme'] || '"system"'))

      // os
      window.document.documentElement.setAttribute('platform', navigator.platform)

      function _$args () {
        const win = window.opener || window.parent || window
        return new URLSearchParams(win.location.search)
      }

      const MODE = _$args().get('mode') || 'normal'

      if (MODE === 'share-preview') {
        Object.defineProperty(window, 'localStorage', {
          value: (function () {
            const s = {}

            Object.defineProperty(s, 'setItem', {
              get: () => {
                return (k, v) => {
                  s[String(k)] = String(v)
                }
              }
            })

            Object.defineProperty(s, 'getItem', {
              get: () => {
                return (k) => {
                  if (Object.prototype.hasOwnProperty.call(s, String(k))) {
                    return s[String(k)]
                  } else {
                    return null
                  }
                }
              }
            })

            Object.defineProperty(s, 'removeItem', {
              get: () => {
                return (k) => {
                  if (Object.prototype.hasOwnProperty.call(s, String(k))) {
                    delete s[String(k)]
                  }
                }
              }
            })

            Object.defineProperty(s, 'clear', {
              get: () => {
                return () => {
                  for (const k in s) {
                    delete s[String(k)]
                  }
                }
              }
            })

            Object.defineProperty(s, 'length', {
              get: () => {
                return Object.keys(s).length
              }
            })

            return s
          })(),
        })
      }
    </script>
    <script src="/api/settings/js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="./index.ts"></script>
  </body>
</html>
